#include "messagewidget.h"
#include "ui_messagewidget.h"

#include <QTimer>

MessageWidget::MessageWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::MessageWidget)
{
    ui->setupUi(this);
    timer = new QTimer(this);
    connect(timer, &QTimer::timeout, [=](){
        qDebug("timer time out");
        hide();
    });
}


MessageWidget::~MessageWidget()
{
    delete ui;
}

void MessageWidget::showMessage(QString msg, int interval)
{
    timer->setInterval(interval * 1000);
    ui->label->setText(msg);
    QWidget *p = static_cast<QWidget*>(parent());
    int posx = p->width() / 2 - 200, posy = p->height() - 50;
    move(posx, posy);
    timer->start();
    show();
}
